export class Student {
 id:string;
 name:string;
 classId:string;
 className:string;
 score:any;
 hearImg:string;
 totalscore:number;
 scoreDesc:string;//学生成绩描述
  answerID:string;
  constructor(id:string,score:string,classId:string,className:string,answerID:string) {
    this.id = id;
    this.score = JSON.parse(score);
    this.classId = classId;
    this.className = className;
    this.answerID = answerID;
    this.countScore();
  }
  initInfo(name,hearImg){
     if(hearImg){
       this.hearImg = 'http://static.lessonplan.cn/'+hearImg;
     }else {
       this.hearImg = '/assets/img/image/datouxiang.png';
       this.name = name;
     }
  }
  //计算学生总成绩
  countScore(){
    this.totalscore = 0;
    Object.keys(this.score).forEach(key=>{
       this.totalscore+=this.score[key];
    });
    if (this.totalscore > 133) this.scoreDesc = '优秀';
    else if (this.totalscore < 111) this.scoreDesc = '一般';
    else this.scoreDesc= '良好';
  }
//  当成绩发生变化时重新计算成绩
  anewScore(score:string){
    this.score = JSON.parse(score);
    this.countScore()
  }
}
